﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MetroLightKit.Controls"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">

  <Style TargetType="local:MetroButton">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="local:MetroButton">
          <Grid x:Name="rootButton" Margin="{TemplateBinding Margin}">
            <VisualStateManager.VisualStateGroups>
              <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal" />
                <VisualState x:Name="MouseOver" />
                <VisualState x:Name="Pressed" />
                <VisualState x:Name="Disabled">
                  <Storyboard>
                    <DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity"
                                     Storyboard.TargetName="DisabledVisualElement" />
                  </Storyboard>
                </VisualState>
              </VisualStateGroup>
              <VisualStateGroup x:Name="FocusStates">
                <VisualState x:Name="Focused">
                  <Storyboard>
                    <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity"
                                     Storyboard.TargetName="FocusVisualElement" />
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="Unfocused" />
              </VisualStateGroup>
              <VisualStateGroup x:Name="MetroStates">
                <VisualState x:Name="NormalState">
                  <Storyboard>
                    <ColorAnimation Duration="0"
                                    To="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"
                                    Storyboard.TargetProperty="(Elipse.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="elipseButton" />
                    <ColorAnimation Duration="0"
                                    To="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"
                                    Storyboard.TargetProperty="(ContentControl.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="presentButton" />
                    <ColorAnimation Duration="0"
                                    To="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"
                                    Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="contentPresenter" />
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Background"
                                                   Storyboard.TargetName="grid2Button">
                      <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
                    </ObjectAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="MouseOverState">
                  <Storyboard>
                    <ColorAnimation Duration="0"
                                    To="{Binding ForegroundOver, RelativeSource={RelativeSource TemplatedParent}}"
                                    Storyboard.TargetProperty="(Elipse.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="elipseButton" />
                    <ColorAnimation Duration="0"
                                    To="{Binding ForegroundOver, RelativeSource={RelativeSource TemplatedParent}}"
                                    Storyboard.TargetProperty="(ContentControl.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="presentButton" />
                    <ColorAnimation Duration="0"
                                    To="{Binding ForegroundOver, RelativeSource={RelativeSource TemplatedParent}}"
                                    Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="contentPresenter" />
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="MetroMouseOverState">
                  <Storyboard>
                    <ColorAnimation Duration="0"
                                    To="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"
                                    Storyboard.TargetProperty="(Elipse.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="elipseButton" />
                    <ColorAnimation Duration="0"
                                    To="{Binding ForegroundOver, RelativeSource={RelativeSource TemplatedParent}}"
                                    Storyboard.TargetProperty="(ContentControl.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="presentButton" />
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Background"
                                                   Storyboard.TargetName="grid2Button">
                      <DiscreteObjectKeyFrame KeyTime="0"
                                              Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}" />
                    </ObjectAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="MetroPressedState">
                  <Storyboard>
                    <ColorAnimation Duration="0"
                                    To="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"
                                    Storyboard.TargetProperty="(Elipse.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="elipseButton" />
                    <ColorAnimation Duration="0"
                                    To="{Binding ForegroundOver, RelativeSource={RelativeSource TemplatedParent}}"
                                    Storyboard.TargetProperty="(ContentControl.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="presentButton" />
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Background"
                                                   Storyboard.TargetName="grid2Button">
                      <DiscreteObjectKeyFrame KeyTime="0"
                                              Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}" />
                    </ObjectAnimationUsingKeyFrames>
                    <DoubleAnimation Duration="0" To="-25"
                                     Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationX)" Storyboard.TargetName="viewButton"
                                     d:IsOptimized="True" />
                    <DoubleAnimation Duration="0" To="-10"
                                     Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="viewButton"
                                     d:IsOptimized="True" />
                    <DoubleAnimation Duration="0" To="1.1"
                                     Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)"
                                     Storyboard.TargetName="contentPresenter" d:IsOptimized="True" />
                    <DoubleAnimation Duration="0" To="1.1"
                                     Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)"
                                     Storyboard.TargetName="contentPresenter" d:IsOptimized="True" />
                    <DoubleAnimation Duration="0" To="-1.0"
                                     Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
                                     Storyboard.TargetName="contentPresenter" d:IsOptimized="True" />
                    <DoubleAnimation Duration="0" To="-2.0"
                                     Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)"
                                     Storyboard.TargetName="contentPresenter" d:IsOptimized="True" />

                  </Storyboard>
                </VisualState>
                <VisualState x:Name="PressedState">
                  <Storyboard>
                    <ColorAnimation Duration="0"
                                    To="{Binding ForegroundOver, RelativeSource={RelativeSource TemplatedParent}}"
                                    Storyboard.TargetProperty="(Elipse.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="elipseButton" />
                    <ColorAnimation Duration="0"
                                    To="{Binding ForegroundOver, RelativeSource={RelativeSource TemplatedParent}}"
                                    Storyboard.TargetProperty="(ContentControl.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="presentButton" />
                    <ColorAnimation Duration="0"
                                    To="{Binding ForegroundOver, RelativeSource={RelativeSource TemplatedParent}}"
                                    Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="contentPresenter" />
                    <DoubleAnimation Duration="0" To="-25"
                                     Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationX)" Storyboard.TargetName="viewButton"
                                     d:IsOptimized="True" />
                    <DoubleAnimation Duration="0" To="-10"
                                     Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="viewButton"
                                     d:IsOptimized="True" />
                    <DoubleAnimation Duration="0" To="1.1"
                                     Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)"
                                     Storyboard.TargetName="contentPresenter" d:IsOptimized="True" />
                    <DoubleAnimation Duration="0" To="1.1"
                                     Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)"
                                     Storyboard.TargetName="contentPresenter" d:IsOptimized="True" />
                    <DoubleAnimation Duration="0" To="-1.0"
                                     Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
                                     Storyboard.TargetName="contentPresenter" d:IsOptimized="True" />
                    <DoubleAnimation Duration="0" To="-2.0"
                                     Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)"
                                     Storyboard.TargetName="contentPresenter" d:IsOptimized="True" />

                  </Storyboard>
                </VisualState>
              </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <StackPanel x:Name="stackContainer" Orientation="{TemplateBinding Orientation}"
                        HorizontalAlignment="Center" Background="Transparent">
              <Viewbox Width="{TemplateBinding ImageWidth}" Height="{TemplateBinding ImageWidth}" x:Name="viewButton">
                <Viewbox.Projection>
                  <PlaneProjection />
                </Viewbox.Projection>
                <Grid x:Name="grid2Button" Height="100" Width="100"
                      Clip="M100,50 C100,77.614235 77.614235,100 50,100 C22.385763,100 0,77.614235 0,50 C0,22.385763 22.385763,0 50,0 C77.614235,0 100,22.385763 100,50 z">
                  <Ellipse Height="100" Width="100" Stroke="{TemplateBinding Foreground}"
                           StrokeThickness="{TemplateBinding CercleThickness}" x:Name="elipseButton" />
                  <local:MetroButtonContent MinWidth="0.5" ImageScaleX="{TemplateBinding ImageScaleX}"
                                            ImageScaleY="{TemplateBinding ImageScaleY}" ImageMargin="{TemplateBinding ImageMargin}"
                                            Style="{TemplateBinding ImageStyle}" Template="{TemplateBinding ImageTemplate}"
                                            Foreground="{TemplateBinding Foreground}" x:Name="presentButton" Background="#FFC41414" />
                </Grid>
              </Viewbox>
              <!--<ContentPresenter Projection="{Binding Path=Projection, ElementName=viewButton}"  x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="{TemplateBinding ContentMargin}"/>-->
              <TextBlock x:Name="contentPresenter" Foreground="{TemplateBinding Foreground}"
                         Text="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"
                         Margin="{TemplateBinding ContentMargin}">
                <TextBlock.Projection>
                  <PlaneProjection />
                </TextBlock.Projection>
                <TextBlock.RenderTransform>
                  <CompositeTransform />
                </TextBlock.RenderTransform>
              </TextBlock>
            </StackPanel>
            <Rectangle x:Name="DisabledVisualElement" Fill="#FFFFFFFF" IsHitTestVisible="false" Opacity="0" RadiusY="3"
                       RadiusX="3" />
            <Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Margin="1" Opacity="0" RadiusY="2"
                       RadiusX="2" />
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>